package com.qf.controller;

import com.qf.entity.Emotions;
import com.qf.service.EmotionsService;
import com.qf.vo.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 心情(Emotions)表控制层
 */

@RestController
@RequestMapping("emotions")
@Tag(name = "日记模块")
public class EmotionsController {
    /**
     * 服务对象
     */
   /* @Resource
    private EmotionsService emotionsService;*/
    // 查询所有心情记录
    @Autowired
    private EmotionsService emotionsService;

    // 查询
    @PostMapping("/selectByEmotions")
    public R selectByEmotions(@RequestBody Emotions emotions) {
        return emotionsService.selectByEmotions(emotions);
    }

    //插入
    @PostMapping("/insertEmotions")
    public R insertEmotions(@RequestBody Emotions emotions) {
        if (emotions.getCreateTime() == null) {
            emotions.setCreateTime(new Date());
        }
        return emotionsService.insertEmotions(emotions);
    }

    //改
    @PostMapping("/updateEmotions")
    public R updateEmotions(@RequestBody Emotions emotions) {
        return emotionsService.updateEmotions(emotions);
    }

    //删除
    @PostMapping("/deleteEmotions")
    public R deleteEmotions(@RequestBody Emotions emotions) {
        return emotionsService.deleteEmotions(emotions);
    }



}

